package cn.edu.ctbu.dp02.service;


import cn.edu.ctbu.dp02.dao.StudentRepository;
import cn.edu.ctbu.dp02.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentService {

    @Autowired
    public StudentRepository studentRepository;

    /**
     * 查询所有学生
     *
     * @return List<Student>
     */

    public List<Student> getAll() {

        return studentRepository.findAll();

    }

    /**
     *新增学生
     * @param student
     * @return
     */

    public Student add(Student student){
        return studentRepository.save(student);
    }

    /**
     * 更新学生信息
     * @param student
     * @return
     */

    public Student update(Student student){
        return studentRepository.save(student);
    }

    /**
     * 删除学生
     * @param id
     */

    public void delete(Integer id){
        studentRepository.deleteById(id);

    }

}